﻿using System;
using System.Collections.Generic;
using System.IO;

namespace SandboxTest
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                AppDomain newAppDomain = null;

                try
                {
                    newAppDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString());

                    string dllPath = AppDomain.CurrentDomain.BaseDirectory + "PluginTest.dll";

                    var ass = newAppDomain.Load(File.ReadAllBytes(dllPath));

                    ass.GetType("PluginTest.Class1").GetMethod("Write").Invoke(null, new object[0]);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                finally
                {
                    if (newAppDomain != null)
                    {
                        AppDomain.Unload(newAppDomain);
                    }
                }
            }
        }
    }
}